#Make file model
#We considered a project containing the files Main.c, Graph.h, Transform.c and Solver.c

DIRECTORIES=${wildcard src/*}

all:
	@echo $(DIRECTORIES)
	@for i in $(DIRECTORIES); do \
		cd $$i; $(MAKE); cd ../..; \
	done



all: m

#Shared object files

#Emits position-independent code suitable for dynamic linking and avoiding any limit on the size of the global offset table. 
#Produces debugging information
#Compiles, links and places the output in the file Transform.o
#Dependency: Transform.c
Transform.o: Transform.c
	gcc -fPIC -g -c -o Transform.o: Transform.c

#Output file: Solver.o
#Dependency: Solver.c
Solver.o: Solver.c
	gcc -fPIC -g -c -o Solver.o: Solver.c
	
#Main file
#Places the output executable file in Main.o
#Dependency: Main.c, Graph.h
Main.o: Main.c Graph.h
	gcc -g -c -o Main.o Main.c

#Replaces or adds file to archive. If archive does not exist, ar creates it.
libMain.a: Main.o Graph.h
	ar rcs Main.a Main.o

#Create shared object
libTransform.so: Transform.o
	gcc -shared -o Transform.so -Wl,-soname,Transform.so Transform.o

#Places output in m
#Searches for Transform shared object
#Dependencies: Main.a Main.o
m: Main.a Main.so
	gcc -g -o m -L. -lme Transform.so

#Removes all files
clean:
	rm -rf *.o lib*.a lib*.so m
